//
//  CookViewController.m
//  project_delicious
//
//  Created by dlios on 15-3-25.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "CookViewController.h"
#import "CookingCell.h"

@interface CookViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) MBProgressHUD *hud;
@end

@implementation CookViewController
- (void)dealloc
{
    [_hud release];
    [_arr release];
    [super dealloc];
}

- (NSURL *)strChangeUrl:(NSString *)str
{
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
    return url;
}
//转菊花
- (void)mbHud
{
    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
    self.hud.labelText = @"Loading...";
    //self.hud.detailsLabelText = @"正在为您加载";
    [self.view addSubview:self.hud];
    [_hud release];
    [_hud show:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    [self mbHud];
    self.title = @"做法";
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"IMG_1345.JPG"]];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSLog(@"%@", self.str);
    [manager GET:self.str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        self.arr = [responseObject objectForKey:@"data"];
        NSLog(@"wowow%@", self.arr);
        UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        tableView.delegate = self;
        tableView.dataSource = self;
        [self.view addSubview:tableView];
        [tableView release];
        [tableView registerClass:[CookingCell class] forCellReuseIdentifier:@"guo"];
        [_hud removeFromSuperview];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"错误:%@", error);
    }];
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CookingCell *cell = [tableView dequeueReusableCellWithIdentifier:@"guo"];
    NSString *str = [[self.arr objectAtIndex:indexPath.row] objectForKey:@"imagePath"];
    [cell.picImageView setImageWithURL:[self strChangeUrl:str]];
    cell.picImageView.layer.cornerRadius = 100;
    cell.picImageView.layer.masksToBounds = YES;
    NSString *order = [[self.arr objectAtIndex:indexPath.row] objectForKey:@"order_id"];
    NSString *describe = [[self.arr objectAtIndex:indexPath.row] objectForKey:@"describe"];
    cell.nameLabel.text = [order stringByAppendingString:[NSString stringWithFormat:@". %@", describe]];
    cell.userInteractionEnabled = NO;
    cell.nameLabel.numberOfLines = 0;
    return cell;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.view.frame.size.height / 3;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
